package com.hunttown.common.domain;

import com.hunttown.common.sharding.client.annotation.ISharding;
import com.hunttown.common.sharding.client.annotation.Sharding;

public class ShardingQuery extends Query implements ISharding {
    private String logicTableName;
    private String shardField;
    private String physicTableName;
    private boolean isItemInAllDataSources;
    private String dataSourceName;

    public ShardingQuery() {
    }

    public ShardingQuery(int pn, int pageSize) {
        super(pn, pageSize);
    }

    public static ShardingQuery page(int pn, int pageSize) {
        return new ShardingQuery(pn, pageSize);
    }

    public static ShardingQuery page(int pn) {
        return new ShardingQuery(pn, 20);
    }

    public static ShardingQuery noPage() {
        return new ShardingQuery();
    }

    public String getLogicTableName() {
        return this.logicTableName;
    }

    public void setLogicTableName(String logicTableName) {
        this.logicTableName = logicTableName;
    }

    public String getShardField() {
        return this.shardField;
    }

    public void setShardField(String shardField) {
        this.shardField = shardField;
    }

    public String getPhysicTableName() {
        return this.physicTableName;
    }

    public void setPhysicTableName(String physicTableName) {
        this.physicTableName = physicTableName;
    }

    public boolean isItemInAllDataSources() {
        return this.isItemInAllDataSources;
    }

    public void setItemInAllDataSources(boolean itemInAllDataSources) {
        this.isItemInAllDataSources = itemInAllDataSources;
    }

    public String getDataSourceName() {
        return this.dataSourceName;
    }

    public void setDataSourceName(String dataSourceName) {
        this.dataSourceName = dataSourceName;
    }

    public void init(Class<?> domainClass) {
        if (!ISharding.class.isAssignableFrom(domainClass)) {
            throw new RuntimeException(domainClass.getName() + "must implements com.hunttown.common.sharding.client.annotation.ISharding");
        } else {
            try {
                ISharding sharding = (ISharding) domainClass.getConstructor().newInstance();
                this.init(sharding);
            } catch (Exception var3) {
                throw new RuntimeException(domainClass.getName() + " must have no args constructor");
            }
        }
    }

    public void init(ISharding sharding) {
        this.setShardField(sharding.getShardField());
        this.setLogicTableName(sharding.getLogicTableName());
        this.setPhysicTableName(sharding.getPhysicTableName());
        this.setItemInAllDataSources(sharding.isItemInAllDataSources());
        this.setDataSourceName(sharding.getDataSourceName());
    }

    public void init(Sharding sharding) {
        this.setShardField(sharding.getShardField());
        this.setLogicTableName(sharding.getLogicTableName());
        this.setPhysicTableName(sharding.getPhysicTableName());
        this.setItemInAllDataSources(sharding.isItemInAllDataSources());
        this.setDataSourceName(sharding.getDataSourceName());
    }

    public String toString() {
        return "ShardingQuery{logicTableName='" + this.logicTableName + '\'' + ", shardField='" + this.shardField + '\'' + ", physicTableName='" + this.physicTableName + '\'' + ", isItemInAllDataSources=" + this.isItemInAllDataSources + ", dataSourceName='" + this.dataSourceName + '\'' + ", " + super.toString() + '}';
    }
}